package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.domain.Strategy;
import cn.wolfcode.wolf2w.business.dto.ChatRequest;
import cn.wolfcode.wolf2w.business.dto.ChatResponse;
import cn.wolfcode.wolf2w.business.service.DeepseekServiceImpl;
import cn.wolfcode.wolf2w.business.service.StrategyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class ChatController {
    @Autowired
    private StrategyServiceImpl strategyService;
    @Autowired
    private DeepseekServiceImpl deepSeekService;

    @PostMapping("/chat")
    public ChatResponse chat(@RequestBody ChatRequest request) throws IOException {
        // 1.查询私有库（es）获取私有数据
        List<Strategy> strategies = strategyService.search(request.getQuestion(), request.getTopK());
        // 2.发送请求到deepseek获取结果
        String answer = deepSeekService.askWithStrategy(request.getQuestion(), strategies);
        // 3.整合结果并返回
        ChatResponse chatResponse = new ChatResponse(answer, strategies);
        return chatResponse;

    }
}
